package com.example.chartview

import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.chartview.bean.ChartEntity
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : AppCompatActivity() {

    private var singlelist: MutableList<Double>? = null

    private var threeList = mutableListOf<ChartEntity>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        singlelist = mutableListOf()

        switch_dash.setOnCheckedChangeListener { _, isChecked ->
            chartView.isShowDash = isChecked
        }

        switch_type.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                chartView.lineType = BROKENLINE
            } else {
                chartView.lineType = CURVELINE
            }
        }

        switch_cover.setOnCheckedChangeListener { _, isChecked ->
            chartView.fillArea = isChecked
        }

        val random = Random()
        val pointList = ArrayList<Int>()
        for (i in 0..10) {
            val nextInt = random.nextInt(30)
            pointList.add(nextInt)

        }
        singlelist!!.add(1.0)
        singlelist!!.add(0.48)
        singlelist!!.add(0.2)
        singlelist!!.add(0.2)
        singlelist!!.add(0.0)
        singlelist!!.add(0.1)
        singlelist!!.add(0.3)

        threeList.add(ChartEntity(500.toDouble(),"文字叙述1"))
        threeList.add(ChartEntity(700.toDouble(),"文字叙述1"))
        threeList.add(ChartEntity(900.toDouble(),"文字叙述1"))

        three_chart.setList(threeList,1000)

        my_single_chart_view.setList(singlelist!!,1.0)
        chartView.dashColor = resources.getColor(R.color.blue)
        chartView.maxY=35
        chartView.setChartPoints(pointList)

    }
}
